﻿using System.Threading.Tasks;
using Loong.Domain.Uow;

namespace Loong.Authorization
{
    public class PermissionChecker : IPermissionChecker
    {
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public PermissionChecker(IUnitOfWorkManager unitOfWorkManager)
        {
            _unitOfWorkManager = unitOfWorkManager;
        }

        public async Task<bool> IsGrantedAsync(long userId, string permission)
        {
            using (var uow = _unitOfWorkManager.Begin())
            {
                await uow.CompleteAsync();

                return string.IsNullOrEmpty(permission);
            }
        }
    }
}
